package com.bluefox.hospital.repository;

import com.bluefox.hospital.model.Announcement;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/**
 * AnnouncementRepository
 */
public interface AnnouncementRepository extends  JpaRepository<Announcement, Long> {

    Page<Announcement> findByType(String type, Pageable pageable);

    Page<Announcement> findByTypeAndStatus(String type, Integer status, Pageable pageable);

    Page<Announcement> findByCreatedBy(String username, Pageable pageable);

    Page<Announcement> findByTypeAndCreatedBy(String type, String username, Pageable pageable);
    /**
     * 按照状态分页查询
     *
     * @param status
     * @param pageable
     * @return
     */
    Page<Announcement> findByStatus(Integer status, Pageable pageable);


    /**
     * 根据类型获取当前最大排序值
     * @param type
     * @return
     */
    @Query(value = "select max(order_field) from announcement t where t.type=?1",nativeQuery = true)
    Integer queryMaxOrderField(String type);
}
